package org.example.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Pattern;
import org.example.anno.NoAuth;
import org.example.pojo.Article;
import org.example.pojo.PageBean;
import org.example.pojo.Result;
import org.example.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@Tag(name = "文章管理", description = "文章管理")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping("article")
    @Operation(summary = "添加文章", description = "添加文章")
    public Result article(@RequestBody @Validated Article article){

        return articleService.add(article);
    }

    @GetMapping()
    @Operation(summary = "文章列表", description = "文章列表")
    @NoAuth()
    public Result<PageBean<Article>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) Integer categoryId,
            @RequestParam(required = false) String state
    ){

        return articleService.list(pageNum, pageSize, categoryId, state);
    }

    @GetMapping("/detail")
    @Operation(summary = "文章详情", description = "文章详情")
    public Result detail( ){

        return Result.success("详情数据");
    }
}
